package com.lazypeople.view;

import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;

public class ButtonCell<T> extends TableCell<T, T> {
    private final Button button;

    public ButtonCell(String buttonText, Runnable onClickAction) {
        this.button = new Button(buttonText);
        this.button.setOnAction(e -> onClickAction.run());
    }

    @Override
    protected void updateItem(T item, boolean empty) {
        super.updateItem(item, empty);
        setGraphic(empty ? null : button);
    }

    // Fixed factory method with explicit type parameters and required arguments
    public static <T> Callback<TableColumn<T, T>, TableCell<T, T>> forTableColumn(String buttonText,
            Runnable onClickAction) {
        return param -> new ButtonCell<>(buttonText, onClickAction);
    }
}